document.addEventListener('DOMContentLoaded', function() {
    // 获取表单元素
    const loginForm = document.getElementById('loginForm');
    const registerForm = document.getElementById('registerForm');

    // 登录表单提交
    loginForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        const username = document.getElementById('loginUsername').value;
        const password = document.getElementById('loginPassword').value;
        const rememberMe = document.getElementById('rememberMe').checked;

        // 简单的表单验证
        if (!username || !password) {
            alert('请填写完整的登录信息！');
            return;
        }

        // TODO: 这里添加实际的登录逻辑
        console.log('登录信息:', { username, password, rememberMe });
        alert('登录成功！');
    });

    // 注册表单提交
    registerForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        const username = document.getElementById('registerUsername').value;
        const email = document.getElementById('registerEmail').value;
        const password = document.getElementById('registerPassword').value;
        const confirmPassword = document.getElementById('confirmPassword').value;

        // 表单验证
        if (!username || !email || !password || !confirmPassword) {
            alert('请填写完整的注册信息！');
            return;
        }

        if (password !== confirmPassword) {
            alert('两次输入的密码不一致！');
            return;
        }

        if (password.length < 6) {
            alert('密码长度不能小于6位！');
            return;
        }

        // 邮箱格式验证
        const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
        if (!emailRegex.test(email)) {
            alert('请输入有效的邮箱地址！');
            return;
        }

        // TODO: 这里添加实际的注册逻辑
        console.log('注册信息:', { username, email, password });
        alert('注册成功！');
    });

    // 密码强度检测
    const passwordInput = document.getElementById('registerPassword');
    passwordInput.addEventListener('input', function() {
        const password = this.value;
        let strength = 0;
        
        if (password.length >= 8) strength++;
        if (password.match(/[a-z]+/)) strength++;
        if (password.match(/[A-Z]+/)) strength++;
        if (password.match(/[0-9]+/)) strength++;
        if (password.match(/[^a-zA-Z0-9]+/)) strength++;

        // 可以根据强度显示不同的提示信息
        console.log('密码强度:', strength);
    });
}); 